const apiUrlJF = "http://all.roywise.cn:8081";
// const apiUrlJF = "http://10.239.28.225";

const urls = ['/workorder/wechat/workorder/query/yibanlist']
const request = (urlType= '', url = '', type = '', date = {}, header = {
}) => {
	var that = this
    return new Promise((resolve, reject) => {
        uni.request({
            method: type,
			// #ifdef H5
            url: apiUrlJF + '/api' +url,
			// #endif
			// #ifdef APP
			url: apiUrlJF + '/api' + url,
			// #endif
            data: date,
            header: {
				'content-type': urls.indexOf(url) != -1 ? 'application/x-www-form-urlencoded' : type == "post" || "put" ? 'application/json' : 'application/x-www-form-urlencoded',
				'Authorization': uni.getStorageSync("token") ? uni.getStorageSync("token") : ""
				},
            dataType: 'json'
        }).then((response) => {
			console.log(response)
			if (response[1].data.code == 200){
				// let [error, res] = response;
				resolve(response[1].data);
			} else if (response[1].data.code == 401){
				uni.showToast({
				    title: response[1].data.msg,
					icon: 'none',
				    duration: 6000
				});
				uni.reLaunch({
					url:'/pages/index/index'
				})
			} else {
				uni.showToast({
				    title: response[1].data.msg,
					icon: 'none',
				    duration: 6000
				});
			}
        }).catch(error => {
            reject(error)
			console.log(error)
        })
    });
	
}
export default request